package net.nagaseyasuhito.kinsenka.service.impl;

import javax.persistence.EntityManager;

import net.nagaseyasuhito.kinsenka.persist.dao.UserDao;
import net.nagaseyasuhito.kinsenka.persist.entity.User;
import net.nagaseyasuhito.kinsenka.service.DebugService;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.wideplay.warp.persist.WorkManager;

public class DebugServiceImpl implements DebugService {

	@Inject
	private Provider<EntityManager> entityManager;

	@Inject
	private UserDao userDao;

	@Inject
	private Provider<WorkManager> workManager;

	@Override
	public void initializeEntity() {
		this.workManager.get().beginWork();
		this.entityManager.get().getTransaction().begin();

		this.persistUser("nagase", "nagase", true);

		this.entityManager.get().getTransaction().commit();
		this.workManager.get().endWork();
	}

	private void persistUser(String signInId, String password, boolean available) {
		User user = new User();
		user.setSignInId(signInId);
		user.setPassword(password);
		user.setAvailable(available);

		this.userDao.persist(user);
	}
}
